﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SF.Common;
using System.Collections;
using System.Data;
using System.Configuration;


namespace SF.Web.UI.mallCs
{
    public class orderList
    {
        public string loaddingUsing(Model.sf_user_info userInfo, string templateType)
        {
            string usingMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    usingMsg = "<link href='css/order.css' rel='stylesheet' />";
                }
            }
            return usingMsg;
        }
        public string loaddingJs(Model.sf_user_info userInfo, string templateType)
        {
            string jsMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    //jsMsg = "function del(orderId) {if (confirm('确认取消订单?')) {$.get('/tools/user_ajax.ashx', { action: 'cancel_order', orderId: orderId }, function (result) {if (result) {alert('取消订单成功！');window.location.reload();} else {alert('网络繁忙，请稍后重试！');}});}} function orderBuy(orderId,addressText) {if (addressText == '') {alert('请先设置收货地址！');return;}location.href = '/api/paypage.aspx?orderId=' + orderId;} function pageUpDn(obj) {var pageNum = 5;var pageIndex = parseInt($('#pageIndex').text());var dateCount = parseInt($('#dataCount').text());if (obj == 'down') {if (pageIndex * pageNum >= dateCount) {return;}pageIndex++;} else {if (pageIndex<=1) {return;}pageIndex--;}$.post('orderList.aspx', { pindex: pageIndex, pnum: pageNum });}";
                    jsMsg = @"function del(orderId) {if (confirm('确认取消订单?')) {$.get('/tools/user_ajax.ashx', 
{ action: 'cancel_order', orderId: orderId }, function (result) {if (result) {alert('取消订单成功！');window.location.reload();} else {alert('网络繁忙，请稍后重试！');}});}} 
function orderBuy(orderId,addressText) {if (addressText == '') {alert('请先设置收货地址！');return;}location.href = '/api/paypage.aspx?orderId=' + orderId;} 
function pageUpDn(obj) {var pageNum = 5;var pageIndex = parseInt($('#pageIndex').text());var dateCount = parseInt($('#dataCount').text());if (obj == 'down') 
{if (pageIndex * pageNum >= dateCount) {return;}pageIndex++;} else {if (pageIndex<=1) {return;}pageIndex--;}
location.href = 'orderList.aspx?pindex='+pageIndex +'&pnum='+pageNum;}";

                    //$.post('orderList.aspx', { pindex: pageIndex, pnum: pageNum });}";
                    //$.post('orderList.aspx?pindex='+pageIndex +'&pnum='+pageNum);}";
                }
            }
            return jsMsg;
        }
        public string loaddingHtml(Model.sf_user_info userInfo, string _pageIndex, string _pageNum, string payStatus, string templateType)
        {
            string htmlMsg = "", appWhere = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    appWhere = Utils.getWhereByInfo(userInfo.busnieseNum, userInfo.appNum, userInfo.templatesNum);
                    BLL.bs_good_order orderInfoBll = new BLL.bs_good_order();
                    int pageIndex = Convert.ToInt32(_pageIndex);
                    int pageNum = Convert.ToInt32(_pageNum);
                    //int type = Convert.ToInt32(_type);
                    int dataNum = 0;
                    string orderListMsg = "", payStatusCn = payStatus == SF.Common.DTEnums.PayStatusEnum.DonePay.ToString() ? "已支付" : "等待支付";
                    //根据条件 获取订单列表
                    DataTable dt = orderInfoBll.GetList(pageNum, pageIndex, "userNum='" + userInfo.userNum + "' and payStatus='" + payStatus + "' and " + appWhere, "id desc", out dataNum, "").Tables[0];
                    foreach (DataRow row in dt.Rows)
                    {
                        SF.Common.DTEnums.PayWayEnum cEnum = (SF.Common.DTEnums.PayWayEnum)Enum.Parse(typeof(SF.Common.DTEnums.PayWayEnum), row["payWay"].ToString());
                        string payWay = Utils.GetEnumDescription(cEnum);

                        orderListMsg += @"<div class='space10'></div><div class='cartlistinner clearfix'>
<div class='cart_orderlist_info'><a href='orderdetail.aspx?orderId=" + row["id"] + "&payStatus=" + payStatus + @"'>
<p class='cart_g_name'>订 单 号：<span class='c-grey'>" + row["orderNum"] + @"</span></p>
<p class='cart_b_name'>支付方式：<span class='c-grey'>" + payWay + @"</span></p>
<p class='cart_b_name'>创建时间：<span class='c-grey'>" + row["createTime"] + @"</span></p>
<p class='space5'></p></a></div><a class='cart_orderlist_p' href='' target='_top' style='display: block;'><span class='c_price'>¥" + row["totalPrice"] + "</span></a>";
                        if (payStatus == SF.Common.DTEnums.PayStatusEnum.DonePay.ToString())
                        {
                            payStatusCn = "已支付";
                            orderListMsg += "<p class='end'>已付款</p></div>";
                        }
                        else
                        {
                            payStatusCn = "等待支付";
                            orderListMsg += "<div><a class='btn btn-large btn-purple end' href='javascript:;' data-islogin='true' data-shopcarthide='true' data-countdown='true' data-carttime='1197' onclick=\"orderBuy('" + row["id"] + "','" + row["receiveInfo"] + "')\">结算</a><a class='ord_del end' href='javascript:;' onclick=\"del('" + row["id"] + "');\">取消订单</a></div></div>";
                            //                            orderListMsg += @"<div><a class='btn btn-large btn-purple end' href='javascript:;' data-islogin='true' data-shopcarthide='true' data-countdown='true' data-carttime='1197' onclick='orderBuy('" + row["orderNum"] + "','" + row["receiveInfo"] + @"')'>结算</a>
                            //<a class='ord_del end' href='javascript:;' onclick='del('" + row["id"] + "');'>取消订单</a></div></div>";
                        }
                    }
                    orderListMsg = string.IsNullOrEmpty(orderListMsg) ? "<div class='space10'></div><div class='cartlistinner clearfix'><div class='cart_orderlist_info'><p class='cart_g_name'><span class='c-grey'>亲，还没有" + payStatusCn + "的订单！ 快去下单吧</span></p></div></div>" : orderListMsg;
                    string pageUpStyle = "background-color:#626670;border-color:#626670;";
                    string pageDownStyle = "background-color:#626670;border-color:#626670;";
                    if (pageIndex > 1)
                    {
                        pageUpStyle = "background-color:rgb(240, 35, 135);border-color:rgb(240, 35, 135);";
                    }
                    if (pageIndex * pageNum < dataNum)
                    {
                        pageDownStyle = "background-color:rgb(240, 35, 135);border-color:rgb(240, 35, 135);";
                    }
                    //htmlMsg = "<body><form id='form1' runat='server'><header id='header' class='u-header clearfix'><div class='u-hd-left f-left'><a href='javascript:history.back();' class='J_backToPrev'><span class='u-icon-px i-hd-back'></span></a></div><span class='u-hd-tit'>订单列表</span><div class='u-hd-right f-right'><a href='user.aspx'><span class='u-icon-px i-hd-home'></span></a></div></header><div id='cart_list'><div class='space10'></div><h2 class='order_sendby clearfix'><span>" + payStatusCn + "</span></h2><div class='cartdiv'>                <div class='cartlist clearfix'>" + orderListMsg + "</div><div class='orderaction clearfix'></div></div><div style='width:100%;height:30px;'></div></div><div class='space10'></div><div class='navbar navbar-default navbar-fixed-bottom'><div class='container nav-current-box' ><button style='" + pageUpStyle + "' id='btnPgUp' name='afresh-check' class='btn btn-long btn-purple' onclick='pageUpDn(up)'>上一页</button><button style='float:right;" + pageDownStyle + "' id='btnPgDn' name='afresh-check' class='btn btn-long btn-purple' onclick='pageUpDn(down)'>下一页</button><span id='pageIndex' style='display:none;'>" + pageIndex + "</span><span id='dataCount' style='display:none;'>" + dataNum + "</span></div></div></form></body>";

                    htmlMsg = @"<body><form id='form1' runat='server'><header id='header' class='u-header clearfix'>
<div class='u-hd-left f-left'><a href='javascript:history.back();' class='J_backToPrev'><span class='u-icon-px i-hd-back'></span></a></div>
<span class='u-hd-tit'>订单列表</span><div class='u-hd-right f-right'><a href='user.aspx'><span class='u-icon-px i-hd-home'></span></a></div></header>
<div id='cart_list'><div class='space10'></div><h2 class='order_sendby clearfix'><span>" + payStatusCn + @"</span></h2>
<div class='cartdiv'>                <div class='cartlist clearfix'>" + orderListMsg + @"</div>
<div class='orderaction clearfix'></div></div><div style='width:100%;height:30px;'></div></div><div class='space10'></div>
<div class='navbar navbar-default navbar-fixed-bottom'><div class='container nav-current-box' >
<a href='javascript:;' style='" + pageUpStyle + @"' id='btnPgUp' class='btn btn-long btn-purple' onclick=" + "\"pageUpDn('up')" + "\"" + @">上一页</a>
<a href='javascript:;' style='float:right;" + pageDownStyle + @"' id='btnPgDn' class='btn btn-long btn-purple' onclick=" + "\"pageUpDn('down')" + "\"" + @">下一页</a>
<span id='pageIndex' style='display:none;'>" + pageIndex + "</span><span id='dataCount' style='display:none;'>" + dataNum + "</span></div></div></form></body>";

//<span id='pageIndex'>" + pageIndex + "</span><span id='dataCount'>" + dataNum + "</span></div></div></form></body>";  //测试测试
                }
            }
            return htmlMsg;
        }
    }
}
